import json
#from tkinter import messagebox
class MysqlDatabases:
    
    #打开文件
    
    def __init__(self):

        with open('users.json', mode='r', encoding='utf-8') as f:
            text=f.read()
        self.users=json.loads(text)

        with open('staffs.json', mode='r', encoding='utf-8') as f:
            text=f.read()
        self.staffs=json.loads(text)

    #检查用户是否存在
    
    def check_login(self,username,password):
        for user in self.users:
            if username==user['username']:
                if password==user['password']:
                    return True,'登录成功'
                else:
                    return False,'登录失败，密码错误'
        return False,'登录失败，用户不存在'

    #添加输入框的内容
    def insert(self,staff):
        self.staffs.append(staff)
    
    

    def check_info(self,check_id):
        for index,staff in enumerate(self.staffs):
            if staff[0]==check_id:
                self.staffs.remove(check_id)
                return index
        return 0

    def search_by_username(self,search_id):
        for staff in self.staffs:
            if staff['员工编号']==search_id:
                return True,staff
        return False,f'{search_id}用户不存在'

    def update(self,sta):
        for staff in self.staffs:
            if staff['员工编号'] == sta['员工编号']:
                staff.update(sta)
                return True
        return False


    def staff_data(self):  #查询表
        return self.staffs


db=MysqlDatabases()
if __name__=='__main__':
    db.check_login('admin','password')
    #print(db.staff_data())